package com.dao.auth;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.common.base.BaseSqlMapDAO;

public class UserRoleDao  extends BaseSqlMapDAO{

	
	
	/**
	 * 根据用户ID 查询出用户所有的角色ID
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<String> getRolesByUserId(Integer userId) throws Exception{
		
		
		return this.getSqlMapClientTemplate().queryForList("muserroles.getRolesByUserId",userId);
	}
	
	
	
	/**
	 * 删除用户所有的角色
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public boolean delUserRolesByUserId(Integer userId) throws Exception{
		
		
		return this.getSqlMapClientTemplate().delete("muserroles.delUserRolesByUserId",userId)>0;
	}
	
	

	/**
	 * 删除角色所有的用户
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public boolean delUserRolesByRoleId(Integer roleId) throws Exception{
		
		
		return this.getSqlMapClientTemplate().delete("muserroles.delUserRolesByRoleId",roleId)>0;
	}
	
	
	/**
	 * 插入用户角色
	 * @param userId
	 * @param roleId
	 * @return
	 * @throws Exception
	 */
	public boolean insertUserRoles(Integer userId,Integer roleId) throws Exception{
		
		Map<String,Integer> map = new HashMap<String,Integer>();
		map.put("userId", userId);
		map.put("roleId", roleId);
		return this.getSqlMapClientTemplate().insert("muserroles.insertUserRoles",map)!=null;
		
	}
}
